#ifndef _ACELOG_H_
#define _ACELOG_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

typedef enum {
    READING_TAG,
    READING_FORMAT,
    READING_LEVEL,
    READING_OUTPUT
} read_conf_status;

typedef enum {
    STDOUT = 1, 
    STDERR,
    TOFILE
} output_type;

typedef enum {
	ACELOG_LEVEL_DEBUG = 0x10,
	ACELOG_LEVEL_INFO  = 0x08,
	ACELOG_LEVEL_WARN  = 0x04,
	ACELOG_LEVEL_ERROR = 0x02,
	ACELOG_LEVEL_FATAL = 0x01
} acelog_level;

typedef struct acelog_ctx_s {
    char *formart;
    unsigned char level_bitmap;

    FILE *fp[5];
    output_type out_type[5];
} acelog_ctx_t;

int acelog_init(const char *path);
int acelog_fini();

void acelog(const char *file, size_t filelen,
	const char *func, size_t funclen,
	long line, int level,
	const char *format, ...);

#ifdef ACEMESH_LOG
#define alog_fatal(...) \
    acelog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \
    ACELOG_LEVEL_FATAL, __VA_ARGS__)
#define alog_error(...) \
    acelog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \
    ACELOG_LEVEL_ERROR, __VA_ARGS__)
#define alog_warn(...) \
    acelog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \
    ACELOG_LEVEL_WARN, __VA_ARGS__)
#define alog_info(...) \
    acelog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \
    ACELOG_LEVEL_INFO, __VA_ARGS__)
#define alog_debug(...) \
    acelog(__FILE__, sizeof(__FILE__)-1, __func__, sizeof(__func__)-1, __LINE__, \
    ACELOG_LEVEL_DEBUG, __VA_ARGS__)

#else

//when close acelog, set log macro empty
#define alog_fatal(...) 
#define alog_error(...) 
#define alog_warn(...) 
#define alog_info(...) 
#define alog_debug(...)

#endif

#ifdef __cplusplus
}
#endif

#endif
